package com.template.app.model.util;

import java.util.Iterator;
import java.util.Set;

public class Utils {
	
	private static final String COMMA = ",";

	public static String setToCommaDelimitedStringId(Set<?> set) {
		StringBuilder sb = new StringBuilder();		
		Iterator<?> it = set.iterator();
		
		while (it.hasNext()) {
			Object o = it.next();
			try {
				sb.append(o.getClass().getMethod("getId").invoke(o));
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
			if (it.hasNext()) {
				sb.append(COMMA);
			}
		}
		
		return sb.toString();
	}
	
	public static String firstToLower(String s) {
		if (s == null || s.isEmpty()) {
			return "";
		}
		
		return s.substring(0, 1).toLowerCase() + s.substring(1);
	}
}
